//
//  CardClassInfo.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/20.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//  会员卡 View

#import "CardView.h"

@implementation CardView

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.bgNameArray = [NSMutableArray arrayWithObjects:@"currencycard_card_black",@"currencycard_card_white",@"currencycard_card_yellow", nil];
        
        self.backgroundColor = CSWhiteColor;
        
        /**
         卡面背景
         */
        UIImageView *bgView = [[UIImageView alloc] init];
        bgView.layer.cornerRadius = 4;
        bgView.layer.masksToBounds = YES;
        [self addSubview:bgView];
        self.bgView = bgView;
        
        /**
         卡名称
         */
        UILabel *cardNameLabel = [[UILabel alloc] init];
        cardNameLabel.font = TitleBoldFont;
        cardNameLabel.text = @"健身年卡";
        cardNameLabel.textColor = CSColorFromRGB(0xffffff);
        [bgView addSubview:cardNameLabel];
        self.cardNameLabel = cardNameLabel;
        
        /**
         线条
         */
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = CSColorFromRGB(0x403f4a);
        [bgView addSubview:lineView];
        self.lineView = lineView;
        
        /**
         会员卡ID
         */
        UILabel *cardIdLabel = [[UILabel alloc] init];
        cardIdLabel.font = [UIFont systemFontOfSize:15.0];
        cardIdLabel.text = @"ID:10022";
        cardIdLabel.textColor = [CSColorFromRGB(0x7b788d) colorWithAlphaComponent:0.6];
        [bgView addSubview:cardIdLabel];
        self.cardIdLabel = cardIdLabel;
        
        
        /**
         限制
         */
        TTTAttributedLabel *limitLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        limitLabel.font = [UIFont systemFontOfSize:15.0];
        limitLabel.textColor = [CSColorFromRGB(0x7b788d) colorWithAlphaComponent:0.7];
        limitLabel.lineBreakMode = NSLineBreakByCharWrapping;
        limitLabel.numberOfLines = 0;
        limitLabel.lineSpacing = 5;
        [bgView addSubview:limitLabel];
        self.limitLabel = limitLabel;
        
        /**
         地址
         */
        TTTAttributedLabel *addressLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        addressLabel.font = [UIFont systemFontOfSize:15.0];
        addressLabel.textColor = CSColorFromRGB(0xffffff);
        addressLabel.lineBreakMode = NSLineBreakByCharWrapping;
        addressLabel.numberOfLines = 0;
        addressLabel.lineSpacing = 5;
        addressLabel.text = @"启航国际店、石景山创业店";
        [bgView addSubview:addressLabel];
        self.addressLabel = addressLabel;;
        
        
        /**
         卡类型
         */
        UILabel *cardClassLabel = [[UILabel alloc] init];
        cardClassLabel.font = MidFont;
        cardClassLabel.text = @"期限卡";
        cardClassLabel.textColor = CSColorFromRGB(0xffffff);
        cardClassLabel.layer.borderColor = CSColorFromRGB(0xffffff).CGColor;
        cardClassLabel.textAlignment = NSTextAlignmentCenter;
        cardClassLabel.layer.cornerRadius = 2;
        cardClassLabel.layer.borderWidth = 0.6;
        cardClassLabel.layer.masksToBounds = YES;
        [bgView addSubview:cardClassLabel];
        self.cardClassLabel = cardClassLabel;
        
        UIView *lineView1 = [[UIView alloc] init];
        lineView1.backgroundColor = LineBackGroundColor;
        [self addSubview:lineView1];
        self.lineView1 = lineView1;
        
        /**
         简介
         */
        UIView *introduceLineView = [[UIView alloc] init];
        introduceLineView.backgroundColor = ButtonBackGroundColor;
        [self addSubview:introduceLineView];
        self.introduceLineView = introduceLineView;
        
        /**
         简介Label
         */
        UILabel *introduceLabel = [[UILabel alloc] init];
        introduceLabel.text = @"简介";
        introduceLabel.font = BoldMidBigFont;
        [self addSubview:introduceLabel];
        self.introduceLabel = introduceLabel;
        
        TTTAttributedLabel *introduceDetailLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        introduceDetailLabel.font = SmallFont;
        introduceDetailLabel.textColor = CSColorFromRGB(0x333333);
        introduceDetailLabel.lineBreakMode = NSLineBreakByCharWrapping;
        introduceDetailLabel.numberOfLines = 0;
        introduceDetailLabel.lineSpacing = 5;
        introduceDetailLabel.text = @"该会员卡有效期为一年，没有次数限制，用完为止，用完为止，用完为止";
        [self addSubview:introduceDetailLabel];
        self.introduceDetailLabel = introduceDetailLabel;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     卡面背景
     */
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        //make.edges.mas_equalTo(self).insets(UIEdgeInsetsMake(10, 13, 0, 13));
        make.top.mas_equalTo(self).offset(10);
        
        make.left.mas_equalTo(self).offset(13);
        
        make.right.mas_equalTo(self).offset(-13);
    }];
    
    /**
     卡名称
     */
    [self.cardNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.bgView).offset(20);
        
        make.left.mas_equalTo(self.bgView).offset(21);
    }];
    
    /**
     会员卡ID
     */
    [self.cardIdLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.bgView).offset(-20);
        
        make.centerY.mas_equalTo(self.cardNameLabel);
    }];
    
    /**
     线条
     */
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.cardNameLabel);
        
        make.top.mas_equalTo(self.cardNameLabel.mas_bottom).offset(15);
        
        make.height.mas_equalTo(3);
        
        make.width.mas_equalTo(40);
    }];
    
    /**
     限制
     */
    [self.limitLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.cardNameLabel);
        
        make.bottom.mas_equalTo(self.bgView).offset(-40);
        
        make.right.mas_equalTo(self.cardClassLabel.mas_left).offset(-3);
    }];
    
    /**
     地址
     */
    [self.addressLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.cardNameLabel);
        
        make.bottom.mas_equalTo(self.limitLabel.mas_top).offset(-12);
        
        make.right.mas_equalTo(self.cardClassLabel.mas_left).offset(-5);
    }];
    
    /**
     卡类型
     */
    [self.cardClassLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.cardIdLabel);
        
        make.height.mas_equalTo(40);
        
        make.width.mas_equalTo(70);
        
        make.bottom.mas_equalTo(self.bgView).offset(-40);
    }];
    
    [self.lineView1 mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.bgView.mas_bottom).offset(5);
        
        make.left.width.mas_equalTo(self);
        
        make.height.mas_equalTo(1);
    }];
    
    /**
     简介
     */
    [self.introduceLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.bgView).offset(2);
        
        make.top.mas_equalTo(self.lineView1.mas_bottom).offset(15);
        
        make.width.mas_equalTo(3);
        
        make.height.mas_equalTo(self.introduceLabel);
    }];
    
    /**
     简介Label
     */
    [self.introduceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.introduceLineView);
        
        make.left.mas_equalTo(self.introduceLineView.mas_right).offset(5);
    }];
    
    [self.introduceDetailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.introduceLabel.mas_bottom).offset(15);
        
        make.left.mas_equalTo(self.introduceLineView);
        
        make.right.mas_equalTo(self).offset(-15);
        
        make.bottom.mas_equalTo(self).offset(-20);
    }];
}

-(void)setSelectRow:(NSInteger)selectRow{
    
    self.bgView.image = [UIImage imageNamed:self.bgNameArray[selectRow % 3]];
    
    //黑色
    if (selectRow % 3 == 0) {
        
        /**
         名字
         */
        
        self.cardNameLabel.textColor = CSColorFromRGB(0xffffff);
        
        /**
         会员卡ID
         */
        
        self.cardIdLabel.textColor = CSColorFromRGBA(0x7b788d,0.6);
        
        /**
         限制
         */
        self.limitLabel.textColor = CSColorFromRGBA(0x7b788d,0.7);
        
        /**
         地址
         */
        self.addressLabel.textColor = CSColorFromRGB(0xffffff);
        
        /**
         卡类型
         */
        self.cardClassLabel.textColor = CSColorFromRGB(0xffffff);
        self.cardClassLabel.layer.borderColor = CSColorFromRGBA(0xffffff,0.2).CGColor;
        
        self.lineView.backgroundColor = CSColorFromRGB(0x403f4a);
        
    }
    else{
        
        /**
         名字
         */
        
        self.cardNameLabel.textColor = CSColorFromRGB(0x0a0a0a);
        
        /**
         会员卡ID
         */
        
        self.cardIdLabel.textColor = CSColorFromRGBA(0x000000,0.6);
        
        /**
         限制
         */
        self.limitLabel.textColor = CSColorFromRGBA(0x000000,0.5);
        
        /**
         地址
         */
        self.addressLabel.textColor = CSColorFromRGB(0x0a0a0a);
        
        /**
         卡类型
         */
        self.cardClassLabel.textColor = CSColorFromRGB(0x0a0a0a);
        self.cardClassLabel.layer.borderColor = CSColorFromRGBA(0x000000,0.2).CGColor;
        
        self.lineView.backgroundColor = CSColorFromRGBA(0x403f4a,0.1);
    }
}

-(void)setCommonCard:(CommonCard *)commonCard{
    
    NSDictionary *typeDict = @{@"2001":@"次卡",@"2002":@"期限卡",@"2003":@"储值卡"};
    
    /**
     名字
     */
    
    self.cardNameLabel.text = commonCard.Name;
    
    /**
     会员卡ID
     */
    
    self.cardIdLabel.text = [NSString stringWithFormat:@"ID:%@",commonCard.ID];
    
    if ([commonCard.IsLimit isEqualToString:@"Y"]) {
        
        self.limitLabel.text = [NSString stringWithFormat:@"可提前预约%@节课、%@、每个会员限购%@张",commonCard.BeforeTimes,commonCard.UnitTimes,commonCard.LimitCards];
    }
    else{
        
        
        self.limitLabel.text = @"没有限制";
    }
    
    
    /**
     地址
     */
    NSString *addrStr = @"";
    
    for (NSString *name in commonCard.ShopName) {
        
        addrStr = [NSString stringWithFormat:@"%@%@、",addrStr,name];
    }
    
    addrStr = addrStr?[addrStr substringWithRange:NSMakeRange(0, addrStr.length - 1)]:@"";
    
    self.addressLabel.text = addrStr;
    
    /**
     卡类型
     */
    self.cardClassLabel.text = [typeDict objectForKey:commonCard.Type];
    
    //简介
    self.introduceDetailLabel.text = commonCard.Desc?commonCard.Desc:@"暂无简介";
}

@end
